/**
 * 分页相关的抽象
 */
export default {
  data () {
    return {
      page: {
        pageNum: 1,
        pageSize: 10,
        total: 0,
        pageNumber:[1,10,15,20,30,40] //页面展示条数
      }
    };
  },
  mounted () {
    // console.log('providers-parent-mounted');
    //this.initValue();
  },
  methods: {
    //占位方法，会被子类覆盖
    initValue () {
      // console.log('parent-initvalue');
    },
    setTotal(total){
      this.page.total = total;
    },
    setPageNum(num){
      this.page.pageNum = num;
    },
    changePage (num) {
      this.setPageNum(num);
      this.initValue();
    },
    setPageSize(size){
      this.page.pageSize = size;
    },
    changeSize (size) {
      this.setPageSize(size);
      this.initValue();
    },
    /**
     * 将params参数与page合并 返回
     * @param params
     * @returns {any}
     */
    paramsPage (params) {
      let _p={
        pageNum: this.page.pageNum,
        pageSize: this.page.pageSize,
      };
      if(params){
        return Object.assign(params, _p);
      }
      return _p;
    },
    // loadGet(url, params) {
    //   let $this=this;
    //   /**
    //    * 链式调用拿到结果解析page，然后流转到then
    //    */
    //   return new Promise((resolve, reject) => {
    //     axios.get(`${url}?t=${new Date().getTime()}`, params).then(res => {
    //       if(res.data && res.data.total) {
    //         $this.page.total = res.data.total;
    //       }
    //       resolve(res.data);
    //     });
    //   });
    // }
  }
};
